package kr.hkit.androidcomplete02.ch13;

import kr.hkit.androidcomplete02.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
import android.widget.TimePicker.OnTimeChangedListener;

public class TimePickerEx extends Activity {
	TimePicker mTime;
	TextView mTxtTime;
	Button mBtn, mBtnNow;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch13_timepickerex);
		
		mTime = (TimePicker) findViewById(R.id.ch13_timepicker);
		mTxtTime = (TextView) findViewById(R.id.ch13_timepicker_tv);
		
		mTime.setOnTimeChangedListener(new OnTimeChangedListener() {
			public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
				mTxtTime.setText(String.format("%d:%d", hourOfDay, minute));
			}
		});
		
		mBtn = (Button) findViewById(R.id.ch13_timepicker_btn);
		mBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				mTime.setIs24HourView(!mTime.is24HourView());
			}
		});
		
		mBtnNow = (Button) findViewById(R.id.ch13_timepicker_btn02);
		mBtnNow.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				String text = String.format("%d시 %d분", mTime.getCurrentHour(), mTime.getCurrentMinute());
				Toast.makeText(TimePickerEx.this, text, Toast.LENGTH_SHORT).show();
			}
		});
	}
}
